package com.rykj.base;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.rykj.R;
import com.rykj.widget.BasePopupWindow;

import androidx.annotation.StringRes;


/**
 * Description: author: zhangsan on 2017/10/12 下午2:15.
 */

public class LoadingDialog extends BasePopupWindow {

    private TextView tvMessage;

    public LoadingDialog(Context context) {
        mContext = context;
        initView();
    }

    private void initView() {
        ColorDrawable colorDrawable = new ColorDrawable(mContext.getResources()
                .getColor(R.color.black));
        colorDrawable.setAlpha(120);
        setBackgroundDrawable(colorDrawable);
        setFocusable(true);
        setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
        View contentView = LayoutInflater.from(mContext)
                .inflate(R.layout.view_loading_dialog, null);
        tvMessage = (TextView) contentView.findViewById(R.id.tv_message);

        setOnDismissListener(this);
        setContentView(contentView);
    }

    public void show(View root, String msg) {
        if (tvMessage != null) {
            tvMessage.setText(msg);
        }

        showAtLocation(root, Gravity.CENTER, 0, 0);
        backgroundAlpha(0.6f);
    }

    public void show(View root, @StringRes int msg) {
        if (tvMessage != null) {
            tvMessage.setText(msg);
        }
    }
}
